<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\BaseController;
use think\captcha\facade\Captcha;
use think\facade\Db;
use think\facade\Request;


class Login extends BaseController
{
    public function index()
    {
        return  view('login');
    }

    public function code(){
          ob_clean();
          return Captcha::create();
    }

    public function login(){

        $username = Request::param('username');
        $password = Request::param('password');
        $validator = new LoginValidat();
        $flag = $validator->check(Request::param());

        if($flag) {

            $user = Db::table('t_sys_user')->where('username', '=', $username)
                ->where('password', '=', md5($password))->select();

            if ($user) {
                return json('登录成功');
            } else {
                return json('登录失败');
            }
        }else{

            return json('登录失败');
        }


    }
}
